//
//  ViewController.m
//  获取键盘高度
//
//  Created by clz on 2019/10/2.
//  Copyright © 2019 clz. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITextFieldDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITextField *textField = [[UITextField alloc]init];
    textField.placeholder = @"测试";
    textField.borderStyle = UITextBorderStyleLine;
    [self.view addSubview:textField];
    textField.frame = CGRectMake(0, 20, self.view.frame.size.width, 44);
    textField.delegate = self;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyborderWillShow:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyborderWillHide:) name:UIKeyboardWillHideNotification object:nil];

    

    
}

- (void)keyborderWillShow:(NSNotification *)sender{
    NSLog(@"键盘将要显示");
    NSDictionary *info = [sender userInfo];
    NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    CGFloat height = keyboardRect.size.height;
    CGFloat width = keyboardRect.size.width;
    NSLog(@"高度 = %f",height);
    NSLog(@"宽度 = %f",width);
    
}

- (void)keyborderWillHide:(NSNotification *)sender{
    NSLog(@"键盘将要消失");
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}





@end
